home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / setSubdivDisplayLevelAndFilt < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.5 KB  |  151 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Dec 15, 1999
  22. //
  23. //  Author:         hmw
  24. //
  25. //  Description:
  26. //        Arguments are passed in $args[] array.  We'll call 
  27. //        the first arg ($args[0]) $levelString.  The second
  28. //        argument $args[1], if present, will set the 
  29. //        displayFilter.  
  30. //
  31. //      Set the subdiv diplay level on the active
  32. //        objects according to $levelString.  If $levelString
  33. //        contains a "+" or "-" the value of level is
  34. //        taken to be relative, otherwise it's
  35. //         absolute.  Returns 1 if setting the level
  36. //        succeeded, and 0 if not.  Probable causes
  37. //        of failure include: poorly fomed $levelString
  38. //        argument (+/- must be the first character of
  39. //        $levelString), attempting to set the
  40. //        display level to a level that doesn't exist, or
  41. //        no valid subdiv surface selected.
  42. //
  43. //  Examples
  44. //        // Decrease current level by two.
  45. //         //
  46. //        setSubdivDisplayLevel "-2";
  47. //        
  48. //        // Set the current display level to three.
  49. //         //
  50. //        setSubdivDisplayLevel 3;
  51. //        
  52. //        // Increase current level by one.
  53. //         //
  54. //        setSubdivDisplayLevel "+1";
  55. //
  56. global proc int setSubdivDisplayLevelAndFilter( string $targets[], 
  57.                                                 string $levelString,
  58.                                                 int    $filter )
  59. {
  60.     int     $foundValidTarget = false;
  61.     int     $setValidValue = false;
  62.  
  63.     string     $target;
  64.  
  65.     int        $isPlus = false;
  66.     int        $isMinus = false;
  67.     int           $level = 0;
  68.  
  69.     // Find out whether the level passed in represents
  70.     // an absolute or a relative change.
  71.     //
  72.     string     $relativeString = substring( $levelString, 1, 1 );
  73.     if( $relativeString == "+" ) {
  74.         $isPlus = true;
  75.         $level = substring( $levelString, 2, size( $levelString ) );
  76.     }
  77.     else if( $relativeString == "-" ) {
  78.         $isMinus = true;
  79.         $level = substring( $levelString, 2, size( $levelString ) );
  80.     }
  81.     else {
  82.         $level = $levelString;
  83.     }
  84.  
  85.     // First process
  86.     //
  87.     string     $cmd;
  88.     string  $errorMessage = "";
  89.  
  90.     for( $target in $targets ) {
  91.         string $attrs[] = `listAttr ($target+".displayLevel") ($target+".displayFilter")`;
  92.         int $isSubdiv = size( $attrs ) == 2;
  93.         if( $isSubdiv == 1 ) {
  94.             $foundValidTarget = true;
  95.  
  96.             int $currLevel = `getAttr ($target + ".displayLevel")`;
  97.             int $newLevel = $level;
  98.             
  99.             if( $isPlus ) {
  100.                 $newLevel = $currLevel + $level;
  101.             }
  102.             else if( $isMinus ) {
  103.                 $newLevel = $currLevel - $level;
  104.             }
  105.  
  106.             int $deepest = `subdiv -query -deepestLevel $target`;
  107.  
  108.             // It's not an error at this point if we try setting above
  109.             // the maximum or below the minimum, but we will cause an
  110.             // an error condition later if NONE of our targets succeeded.
  111.             // In that case, set the error message to be something 
  112.             // useful, even though it won't contain info about all the
  113.             // targets that caused it to fail.
  114.             //
  115.             if(( $newLevel <= $deepest )
  116.             && ( $newLevel >= 0 ))
  117.             {   
  118.                 $setValidValue = true;
  119.                 // Set the display level
  120.                 //
  121.                 $cmd = ( "setAttr \"" + $target + ".displayLevel\" " + 
  122.                          $newLevel + "; " );
  123.  
  124.                 // Set the display filter
  125.                 //
  126.                 $cmd += ( "setAttr \"" + $target + ".displayFilter\" " + 
  127.                           $filter + "; " );
  128.  
  129.                 catch( `evalEcho $cmd` );
  130.             } else if( $newLevel > $deepest ) {
  131.                 $errorMessage = ("Cannot display finer than level "+$deepest + ".");
  132.             } else if( $newLevel < 0 ) {
  133.                 $errorMessage = ("Cannot display coarser than level 0.");
  134.             }
  135.         }
  136.     }
  137.     
  138.     // No valid targets on active list.
  139.     //
  140.     if( $foundValidTarget == 0 ) {
  141.         error( "No valid subdivision surface or subdivision component selected." );
  142.     }
  143.     // None of our targets worked.
  144.     //
  145.     else if( $setValidValue == 0 ) {
  146.         error( $errorMessage );
  147.     }
  148.  
  149.     return $setValidValue;
  150. }
  151.